using System;
using Animoso.Domain;
using Animoso.Domain.Data;
using NHibernate;
using NHibernate.Criterion;

namespace Animoso.Data
{
    public class IntroductionRepository : BaseRepository<Introduction>, IIntroductionRepository
    {
        public bool HasIntroductionByYear(int year)
        {
            Introduction introduction = GetIntroductionByYear(year);
            if(introduction == null)
                return false;
            return true;
        }

        public Introduction GetIntroductionByYear(int year)
        {
            using(ISession session = SessionProvider.GetSession())
            {
                var introduction = session.CreateCriteria<Introduction>()
                    .Add(Restrictions.Eq("Year", year))
                    .UniqueResult<Introduction>();
                return introduction;
            }
        }
    }
}